<template>
	<view>
		<view class="test">
			<web-view :webview-styles="webviewStyles" :src="htmlSrc" @message="handleMessage"></web-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newsContent:"",
				htmlSrc:"",
				webviewStyles:{
					progress:"#FF3333"
				},
				token: '',
                thumb:"",
                title:""
			}
		},
		onLoad(options) {
			const _this = this;
		    _this.token = uni.getStorageSync('token');
			console.log(_this.token)
			console.log(options)
		    if(options.link.indexOf('?') > -1){
				this.htmlSrc = options.link;
			}else{
				this.htmlSrc = options.link + '?id=' + options.id;
			}
            this.htmlSrc += "&type=1";
		    if(_this.token) {
		        this.htmlSrc += '&token=' + _this.token;
		    }
            _this.thumb = options.thumb;
            _this.title = options.title;
		},
		methods: {
            // 分享到微信聊天页面
            shareWxSession() {
                this.share("weixin", "WXSceneSession")
            },
            // 分享到微信朋友圈
            shareWxTimeline() {
                this.share("weixin", "WXSenceTimeline")
            },
            // 分享到微博
            shareSinaWeibo() {
                uni.share({
                    provider: 'sinaweibo',
                    type: 1,
                    href: this.htmlSrc,
                    title: "中房报分享",
                    summary: this.title,
                    success: function (res) {
                        console.log("success:" + JSON.stringify(res));
                    },
                    fail: function (err) {
                        console.log("fail:" + JSON.stringify(err));
                    }
                });
            },
            // 分享到qq
            shareQq() {
                this.share("qq")
            },
            share(type, scene) {
                uni.share({
                    provider: type,
                    scene: scene,
                    type: 0,
                    href: this.htmlSrc,
                    title: "中房报分享",
                    summary: this.title,
                    imageUrl: this.thumb ? this.thumb : "http://cmszfb.oss-cn-beijing.aliyuncs.com/u/cms/www/202005/11234934cm3y.png",
                    success: function (res) {
                        console.log("success:" + JSON.stringify(res));
                    },
                    fail: function (err) {
                        console.log("fail:" + JSON.stringify(err));
                    }
                });
            },
            handleMessage(evt) {
                let action = evt.detail.data[0].action;
                if(action == 'share-tx-weChat') {
                    this.shareWxSession();
                } else if(action == 'share-tx-friends') {
                    this.shareWxTimeline();
                } else if(action == 'share-xl-weiBo') {
                    this.shareSinaWeibo();
                } else if(action == 'share-xl-qq') {
                    this.shareQq();
                }
            }
		}
	}
</script>

<style>

</style>
